// filename: frontend/src/store/search.js (已升级为支持跳转任务)

import { defineStore } from "pinia";
import { ref } from "vue";

export const useSearchStore = defineStore("search", () => {
  // 旧的 pendingSearch (用于分类页) 保持不变
  const pendingSearch = ref(null);
  const setPendingSearch = (type, value) => {
    pendingSearch.value = { type, value };
  };
  const clearPendingSearch = () => {
    pendingSearch.value = null;
  };

  // 【核心新增】用于存储跨页跳转任务的状态
  const pendingJump = ref(null);

  // 【核心新增】设置跳转任务的 action
  const setPendingJump = (jumpTask) => {
    pendingJump.value = jumpTask;
  };

  // 【核心新增】清除跳转任务的 action
  const clearPendingJump = () => {
    pendingJump.value = null;
  };

  return {
    pendingSearch,
    setPendingSearch,
    clearPendingSearch,
    
    pendingJump,       // <-- 暴露
    setPendingJump,    // <-- 暴露
    clearPendingJump,  // <-- 暴露
  };
});